
function GM:ContextMenuOpen()
	local rest = vgui.Create("SpawnIcon")
	rest:SetSize(64,64)
	rest:SetPos(ScrW() * .5, ScrH() * .5)
	rest:SetModel("models/healthvial.mdl")
	gui.EnableScreenClicker(true)
	return true
end

surface.CreateFont("Tahoma", 12, 500, true, false, "Hud_12" )
surface.CreateFont("Typenoksidi", 14, 500, true, false, "TraceInfo" )
surface.CreateFont("Mortbats", 36, 500, true, false, "ZombieTrace" )
DrawTarget = nil
DrawTime = nil
function GM:HUDDrawTargetID()

	if not ToggleHUD then return end

	local text = ""
	local text2 = ""
	local enttype
	local cc = Color(0,0,0,255)

	local start = LocalPlayer():GetShootPos() + (LocalPlayer():GetCursorAimVector() * 20)
	local finish = LocalPlayer():GetShootPos() + (LocalPlayer():GetCursorAimVector() * 99999)
	local tracedata = {}
	tracedata.start = start
	tracedata.endpos = finish
	tracedata.filter = LocalPlayer()
	local trace = util.TraceLine(tracedata) 

	if (!trace.Hit) then return end
	if (!trace.HitNonWorld and not DrawTarget) then return end
	
	if LocalPlayer():Team() == TEAM_UNDEAD then
		if trace.Entity:IsPlayer() and ToggleHUD then
			if trace.Entity:Team() == TEAM_HUMANS then
				DrawTarget = trace.Entity
				DrawTime = CurTime() + 2.5
			end
		elseif string.find(trace.Entity:GetClass(),"prop_door") or string.find(trace.Entity:GetClass(),"breakable") or string.find(trace.Entity:GetClass(),"prop_phys") then
			if ToggleHUD then
				DrawTarget = trace.Entity
				DrawTime = CurTime() + 2.5
			end
		end
		if DrawTarget != nil and DrawTarget != NULL then
			local x,y = ScrW() * 0.5, ScrH() * 0.5
			if DrawTarget:IsValid() and DrawTarget:IsPlayer() then
				local hp = math.Clamp(DrawTarget:Health(),0,100)
				local ratio = hp/100
				local hpred=255*(1-ratio)
				local hpgreen=200*ratio
				local hpblue =40*ratio
				local hpcolor = Color(hpred,hpgreen,hpblue,TimedSin(0.1,100,160,10))
				draw.DrawText("t", "ZombieTrace", x, y, hpcolor,TEXT_ALIGN_CENTER)			
			elseif DrawTarget:IsValid() and not DrawTarget:IsPlayer() then
				draw.DrawText(":", "ZombieTrace", x, y, Color(255,0,0,TimedSin(0.1,100,160,10)),TEXT_ALIGN_CENTER)
			end
		else
			DrawTime = nil
		end
		if DrawTime then
			if DrawTime < CurTime() then 
				DrawTime = nil 
				DrawTarget = nil 
			end
		end
		return
	end
			
	if trace.Entity:IsPlayer() then
		if trace.Entity != DrawTarget then
			DrawDist = nil
		end
		DrawTarget = trace.Entity
		DrawTime = CurTime() + 2.5
	elseif string.find(trace.Entity:GetClass(),"prop_physic") then
		local tbl = Inventory.FindTable(trace.Entity:GetModel())
		if tbl then
			if trace.Entity != DrawTarget then
				DrawDist = nil
			end
			DrawTarget = trace.Entity
			DrawTime = CurTime() + 2.5
		end
	elseif string.find(trace.Entity:GetClass(),"sent_") or string.find(trace.Entity:GetClass(),"bomb_") or string.find(trace.Entity:GetClass(),"npc") then
		if trace.Entity != DrawTarget then
			DrawDist = nil
		end
		DrawTarget = trace.Entity
		DrawTime = CurTime() + 2.5
	end
		
	if trace.Entity:GetOwner() == LocalPlayer() then
		enttype = nil
	end

	if LocalPlayer():Team() == TEAM_HUMANS then
		if DrawTime and DrawTarget:IsValid() then
			local x = ScrW() * 0.5
			local y = ScrH() * 0.5
			if DrawTarget:IsPlayer() and DrawTarget:Team() == LocalPlayer():Team() then
				surface.SetDrawColor(0, 220, 0, 220)
				surface.DrawLine(x-2, y, x+2, y)
				surface.DrawLine(x, y-2, x, y+2)
				text = DrawTarget:Name()..": "..math.Clamp(DrawTarget:Health(),0,9000).." HP"
				cc = team.GetColor(DrawTarget:Team())
				local dcc = Color(220,0,0,220)
				if DrawTarget:Health() > 60 then
					dcc = team.GetColor(DrawTarget:Team())
				end
				local obbmin = (DrawTarget:GetPos()+(LocalPlayer():GetRight() * -25)):ToScreen()
				local obbmax = (DrawTarget:GetPos()+(LocalPlayer():GetRight() * 21) + (DrawTarget:GetUp() * 72)):ToScreen()
				if not obbmin.visible or not obbmax.visible then 
					DrawTime = nil 
					DrawTarget = nil 
				return end
				surface.SetDrawColor( cc.r, cc.g, cc.b, 220 )
				surface.DrawLine( obbmin.x, obbmax.y, obbmax.x, obbmax.y )
				surface.DrawLine( obbmin.x, obbmin.y, obbmin.x, obbmax.y )
				if LocalPlayer():GetPos():Distance(DrawTarget:GetPos()) < 1200 then
				
					local dx, dy = obbmin.x, obbmax.y - 16
				
					surface.SetFont("Hud_12")
					surface.SetDrawColor(30,30,30,170)
					local dw, dh = surface.GetTextSize(text)
					dw, dh = dw + 4, dh + 4
					surface.DrawRect(dx, dy - 1, dw, dh)

					draw.SimpleText( text, "Hud_12", dx + 2, dy, dcc )
				end
			elseif DrawTarget:IsPlayer() and DrawTarget:Team() == TEAM_UNDEAD then
				surface.SetDrawColor(220, 0, 0, 220)
				surface.DrawLine(x-2, y, x+2, y)
				surface.DrawLine(x, y-2, x, y+2)
			elseif string.find(DrawTarget:GetClass(),"npc")then
				surface.SetDrawColor(220, 0, 0, 220)
				surface.DrawLine(x-2, y, x+2, y)
				surface.DrawLine(x, y-2, x, y+2)
			elseif string.find(DrawTarget:GetClass(),"prop_physic") then
				if LocalPlayer():GetPos():Distance(DrawTarget:GetPos()) < 1500 then
					surface.SetDrawColor(70, 80, 220, 220)
					surface.DrawLine(x-2, y, x+2, y)
					surface.DrawLine(x, y-2, x, y+2)
					
					local tbl = Inventory.FindTable(string.lower(DrawTarget:GetModel()))
					local text = tbl.Name
					
					local min,max,cen = DrawTarget:LocalToWorld(DrawTarget:OBBMins()), DrawTarget:LocalToWorld(DrawTarget:OBBMaxs()), DrawTarget:LocalToWorld(DrawTarget:OBBCenter())
					local minl,maxl,cenp = min:Distance(cen), max:Distance(cen), cen:ToScreen()
					local minp = (cen + (LocalPlayer():GetRight() * (-1 * minl)) + (LocalPlayer():GetUp() * (-1 * minl))):ToScreen()
					local maxp = (cen + (LocalPlayer():GetRight() * maxl) + (LocalPlayer():GetUp() * maxl)):ToScreen()
					if not cenp.visible then 
						DrawTime = nil 
						DrawTarget = nil 
					return end
					surface.SetDrawColor( 0, 0, 220, 200 )
					surface.DrawLine( minp.x, maxp.y, maxp.x, maxp.y )
					surface.DrawLine( minp.x, maxp.y, minp.x, minp.y )
					
					surface.SetFont("Hud_12")
					surface.SetDrawColor(30,30,30,170)
					local dw, dh = surface.GetTextSize(text)
					dw, dh = dw + 4, dh + 4
					surface.DrawRect(minp.x, maxp.y - 17, dw, dh)
					
					draw.SimpleText( text, "Hud_12", minp.x + 2, maxp.y - 16, Color(250,250,250,250), 0)
				end
			elseif string.find(DrawTarget:GetClass(),"sent_") or string.find(DrawTarget:GetClass(),"bomb_") then
				if LocalPlayer():GetPos():Distance(DrawTarget:GetPos()) < 1500 then
					local class = DrawTarget:GetClass()
					if string.find(class,"antidote") or string.find(class,"weapon") then
						surface.SetDrawColor(70, 80, 220, 220)
						surface.DrawLine(x-2, y, x+2, y)
						surface.DrawLine(x, y-2, x, y+2)
						
						local tbl = Inventory.FindWeaponTable(string.lower(DrawTarget:GetModel()))
						local text = tbl.Name
						
						local min,max,cen = DrawTarget:LocalToWorld(DrawTarget:OBBMins()), DrawTarget:LocalToWorld(DrawTarget:OBBMaxs()), DrawTarget:LocalToWorld(DrawTarget:OBBCenter())
						local minl,maxl,cenp = min:Distance(cen), max:Distance(cen), cen:ToScreen()
						local minp = (cen + (LocalPlayer():GetRight() * (-1 * minl)) + (LocalPlayer():GetUp() * (-1 * minl))):ToScreen()
						local maxp = (cen + (LocalPlayer():GetRight() * maxl) + (LocalPlayer():GetUp() * maxl)):ToScreen()
						if not cenp.visible then 
							DrawTime = nil 
							DrawTarget = nil 
						return end
						surface.SetDrawColor( 0, 0, 220, 200 )
						surface.DrawLine( minp.x, maxp.y, maxp.x, maxp.y )
						surface.DrawLine( minp.x, maxp.y, minp.x, minp.y )
						
						surface.SetFont("Hud_12")
						surface.SetDrawColor(30,30,30,170)
						local dw, dh = surface.GetTextSize(text)
						dw, dh = dw + 4, dh + 4
						surface.DrawRect(minp.x, maxp.y - 17, dw, dh)
						
						draw.SimpleText( text, "Hud_12", minp.x + 2, maxp.y - 16, Color(250,250,250,250), 0)
					else
						surface.SetDrawColor(220, 0, 0, 220)
						surface.DrawLine(x-2, y, x+2, y)
						surface.DrawLine(x, y-2, x, y+2)
					end
				end
			end
			if DrawTime < CurTime() then 
				DrawTime = nil 
				DrawTarget = nil 
			end
		else
			DrawTime = nil
		end
	end
end
